package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.dao.CategoryReportMapper;
import com.qingcheng.pojo.order.CategoryReport;
import com.qingcheng.service.order.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import tk.mybatis.mapper.entity.Example;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName: qingcheng_parent
 * @ClassName: CategoryReportServiceImpl
 * @Time: 2019/6/29
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
@Service
public class CategoryReportServiceImpl implements CategoryReportService {

    @Autowired
    private CategoryReportMapper categoryReportMapper;

   @Scheduled(cron = "0 0 1 * * ? *")
   public void timeingFindCategoryReport(){
//       LocalDate localDate = LocalDate.now().minusDays(1);
       LocalDate localDate = LocalDate.of(2019,1,26);
       List<CategoryReport> categoryReports = categoryReportMapper.findCategoryReport(localDate);
       for (CategoryReport categoryReport : categoryReports) {
           System.out.println(categoryReport);
           categoryReportMapper.insert(categoryReport);
       }
   }

    @Override
    public List<Map> category1Count0(String date1, String date2) {
        return categoryReportMapper.category1Count0(date1 ,date2);
    }

    @Override
    public List<Map> category1Count(String date1, String date2) {
        return categoryReportMapper.category1Count(date1 ,date2);
    }

    @Override
    public List<CategoryReport> findCategoryReport(LocalDate localDate) {
        String date = "2019-01-26";
        System.out.println(localDate);
        Example example = new Example(CategoryReport.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("countDate",date);
        return categoryReportMapper.selectByExample(example);
    }

    @Override
    public List<CategoryReport> dateOrder(String date) {
        return categoryReportMapper.findCategoryReport2(date);
    }
}
